//
//  BEOrderDetailViewModel.swift
//  BEGlobalOiler
//
//  Created by KKING on 16/9/19.
//  Copyright © 2016年 Bullseye Energy pte ltd. All rights reserved.
//

import UIKit

class BEOrderDetailViewModel: NSObject {
    //懒加载视图模型
    var modelData: BEOrderDetailModel = BEOrderDetailModel(dict: ["": "" as AnyObject])
}


extension BEOrderDetailViewModel{
    
    func loadOrderDetailData(orderId: Int64,finished: @escaping (_ success: Bool, _ tip: String) -> ()) {
        BENetworkTools.shareNetworkTool.loadOrderDetailData(orderId: orderId) { (success, result, error) in
            
            guard let resultjson = result else {
                finished(false, "Network fault!")
                return
            }
            if resultjson["success"] == true {
//                print(resultjson)
                let modelData  = BEOrderDetailModel(dict: resultjson["result"].dictionaryObject! as [String : AnyObject])
                self.modelData = modelData
                finished(true, "Load data success")
            } else {
                finished(false, resultjson["message"].stringValue)
            }
        }
    }
}

/*
 {
 "message" : "操作成功！",
 "result" : {
 "id" : "3810619186896568320",
 "rigLocation" : "蒋虎测试油井地址",
 "orderSn" : "D160918302000000302",
 "rigId" : "3810615159270014976",
 "orderTalentRefVOList" : [
 {
 "status" : 1,
 "orderId" : "3810619186896568320",
 "remark" : "测试1",
 "id" : "3810632762688405504",
 "mobile" : "string",
 "talentId" : "3810630646334881793",
 "isNeedBox" : 1,
 "talentName" : "talent1",
 "photo" : ""
 },
 {
 "status" : 1,
 "orderId" : "3810619186896568320",
 "remark" : "测试2",
 "id" : "3810632762726154240",
 "mobile" : "123456",
 "talentId" : "3810632019461931009",
 "isNeedBox" : 0,
 "talentName" : "talent2",
 "photo" : ""
 }
 ],
 "expectStartTime" : "2016-09-18 06:55:43",
 "orderStatusName" : "Submitted",
 "actualEndTime" : "2016-09-18 06:55:43",
 "orderStatus" : 1,
 "companyName" : "中国移动",
 "rigName" : "蒋虎测试场所",
 "expectEndTime" : "2016-09-18 06:55:43",
 "estimateAmount" : 19800,
 "actualStartTime" : "2016-09-18 08:22:31",
 "companyId" : "3806678427688370176"
 },
 "success" : true
 }*/
